//@author A0097013L
package logic;
import gui.GuiMain;

import java.util.Calendar;
import java.util.Collections;

import memory.GenericEvents;
import memory.Memory;


public class Add {

	private static final String TASK = "Task";
	private static final String DEADLINE = "Deadline";
	private static final String EVENT = "Event";

	static GenericEvents task;
	static GenericEvents deadline;
	static GenericEvents event;

	public Add() {

	}

	// Adds given parameters as attributes for GenericEvents object and add into memory.
	// Name is also added into autocomplete, sorted by urgency and saved state in history
	public static void addToMemory(String type, String name, String description, Calendar start, Calendar end, Memory memory) {
		assert name.length() >0; // for valid taskname
		Display.displayClear();
		switch (type) {
		
		case TASK:
			task = new GenericEvents(type, name, description);
			memory.add(task);
			Display.displayDetailed(task);
			break;
		
		case DEADLINE:
			deadline = new GenericEvents(type, name, description, end);
			memory.add(deadline);
			Display.displayDetailed(deadline);
			break;
		
		case EVENT:
			event = new GenericEvents(type, name, description, start, end, 0);
			memory.add(event);
			Display.displayDetailed(event);
			break;
		}
		
		//Add and sort item names into autocomplete list
		GuiMain.words.add(name);
		Collections.sort(GuiMain.words);
		
		Sort.sort(memory.getList());
		History.advance(memory);
	}
}
